package com.farecrawler.app.model;

import java.util.Calendar;

import org.springframework.stereotype.Component;

@Component("flightRequest")
public class FlightRequest {
	
	private Calendar departureDate;
	private Calendar arrivalDate;
	private String origin;
	private String destination;
	
	/**
	 * Constructor
	 */
	public FlightRequest() {	
	}
	
	/**
	 * Constructor
	 */
	public FlightRequest(Calendar departDate, Calendar arrivalDate, String origin, String destination) {
		this.departureDate = departDate;
		this.arrivalDate = arrivalDate;
		this.origin = origin;
		this.destination = destination;
	}
	
	public Calendar getDepartureDate() {
		return departureDate;
	}
	
	public Integer getDepartureDay() {
		return getCalendarFieldValues(departureDate, Calendar.DATE);
	}
	
	public Integer getDepartureMonth() {
		Integer month = getCalendarFieldValues(departureDate, Calendar.MONTH);
		month += 1; // plus one because Calendar treat January as 0
		
		return month;
	}
	
	public Integer getDepartureYear() {
		return getCalendarFieldValues(departureDate, Calendar.YEAR);
	}
	
	public void setDepartureDate(Calendar departureDate) {
		this.departureDate = departureDate;
	}
	public Calendar getArrivalDate() {
		return arrivalDate;
	}
	
	public Integer getArrivalDay() {
		return getCalendarFieldValues(arrivalDate, Calendar.DATE);
	}
	
	public Integer getArrivalMonth() {
		Integer month = getCalendarFieldValues(arrivalDate, Calendar.MONTH);
		month += 1; // plus one because Calendar treat January as 0
		
		return month;
	}
	
	public Integer getArrivalYear() {
		return getCalendarFieldValues(arrivalDate, Calendar.YEAR);
	}
	
	public void setArrivalDate(Calendar arrivalDate) {
		this.arrivalDate = arrivalDate;
	}
	public String getOrigin() {
		return origin;
	}
	public void setOrigin(String origin) {
		this.origin = origin;
	}
	public String getDestination() {
		return destination;
	}
	public void setDestination(String destination) {
		this.destination = destination;
	}
	
	protected Integer getCalendarFieldValues(Calendar date, int calendarField) {
		return date.get(calendarField);
	}

}
